package array

import (
	"fmt"
	"gopkg.in/fatih/set.v0"
	"strings"
)


func ArrayToString(array []interface{}) string {
	return strings.Replace(strings.Trim(fmt.Sprint(array), "[]"), " ", ",", -1)
}

type SetNew struct {
	arrs map[int]set.Interface
}

func Set(arrs ...[]interface{}) *SetNew{
	var allArr=make(map[int] set.Interface)
	var i int
	for _, arr := range arrs {
		if len(arr)>0 {
			allArr[i] =set.New(set.ThreadSafe)
			for _, v := range arr {
				allArr[i].Add(v)
			}
			i++
		}
	}
	fmt.Println(allArr)
	s := &SetNew{
		arrs: allArr,
	}
	return s
}
func (s *SetNew) Intersection() set.Interface{
	var aa set.Interface
	arrs:=s.arrs
	if len(arrs)<1 {
		return aa
	}
	if len(arrs)==1{
		return arrs[0]
	}
	var i int=0
	for _, arr := range arrs {
		if(i==0){
			aa=arr
		}else{
			aa=set.Intersection(aa,arr)
		}
	}
	return aa

}

func Intersection(arrs ...[]interface{}) set.Interface{
	allArr:=make(map[int] set.Interface)
	var i int=0
	var aa set.Interface
	for _, arr := range arrs {
		if len(arr)>0 {
			allArr[i] =set.New(set.ThreadSafe)
			for _, v := range arr {
				allArr[i].Add(v)
			}
			if i==0{
				aa=allArr[i]
			}else{
				aa=set.Intersection(aa,allArr[i])
			}
			i++
		}
	}
	return aa
}

